
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        :permission="permissionList"
        :upload-after="uploadAfter"
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
      >
        <template  slot="menu"
          slot-scope="scope">
          <el-button v-if="approval_btn" icon="el-icon-check" size="mini" type="text" @click="approval" >审批</el-button>
          <el-button v-if="scope.row.file!=null"
            type="text"
            size="mini"
            icon="el-icon-download"
            @click="download(scope.row)">下载 </el-button>
        </template>
        <template slot="menuLeft">
          <el-button type="primary" v-if="submitBatch_btn" size="small" @click="submitBatch">批量提交</el-button>
          <el-button type="primary" v-if="sendBatch_btn" size="small" @click="sendBatch">批量下发</el-button>
          <el-button type="primary" size="small" @click="getExcel">导出</el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import {
  fetchList,
  getObj,
  addObj,
  putObj,
  delObj,
  download,
  sendObj,
  submitObj,
  approvalObj
} from "@/api/subwaystm/swstapplynetworkcheckpassengeraffairsshenpi";
import { tableOption } from "@/const/crud/subwaystm/swstapplynetworkcheckpassengeraffairsshenpi";
import { mapGetters } from "vuex";
import { handleDownFile } from '@/util/util'
import baseCrud from '@/mixins/base-crud'

export default {
  name: "swstapplynetworkcheckpassengeraffairs",
  mixins: [baseCrud('subwaystm/swstapplynetworkcheckpassengeraffairsshenpi')],
  data() {
    return {
      fileAddress:''
    };
  },
  created() {
    this.dycColumn(this.userInfo.belongToLine)
     this.approval_btn = this.permissions["stm_swstapplynetworkcheckpassengeraffairs_approval"];
    this.sendBatch_btn = this.permissions["stm_swstapplynetworkcheckpassengeraffairs_sendBatch"];
    this.submitBatch_btn = this.permissions["stm_swstapplynetworkcheckpassengeraffairs_submitBatch"];
    console.log(this.userInfo.belongToLine)
  },
  computed: {
    ...mapGetters(["permissions","userInfo"]),
    permissionList() {
      return {
        addBtn: this.vaildData(
          this.permissions.stm_swstapplynetworkcheckpassengeraffairs_add,
          false
        ),
        delBtn: this.vaildData(
          this.permissions.stm_swstapplynetworkcheckpassengeraffairs_del,
          false
        ),
        editBtn: this.vaildData(
          this.permissions.stm_swstapplynetworkcheckpassengeraffairs_edit,
          false
        )
      };
    },

  },
  methods: {
    sendBatch: function() {
         if (
        this.$refs.crud.tableSelect.length < 1
      ) {
        this.$message.error("请勾选数据");
        return false;
      }
      let ids =this.$refs.crud.tableSelect;
      sendObj(ids)
        .then(data => {
          this.$message.success("下发成功");
           this.getList(this.page);
          done();
        })
        .catch(() => {
          loading();
        });
    },

     approval: function(row, index, done, loading) {
      approvalObj(row)
        .then(data => {
          this.$message.success("审批成功");
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },

    dycColumn:function(val){
      var lineCode =this.findObject(this.tableOption.column,'lineCode')
      var stationCode =this.findObject(this.tableOption.column,'stationCode')
      console.log(lineCode)
      if(val!=true){
        console.log("车站")
        lineCode.hide=true
         stationCode.hide=true
      }else{
           console.log("线网")
        lineCode.hide=false
         stationCode.hide=false
      }
    },
    download : function(row){
      handleDownFile(row.file);
    },
    handleUpdate: function(row, index, done, loading) {
        if(row.applyStatus!='0'){
        this.$message.error("已提交不能修改");
        return false;
            }
      putObj(row)
        .then(data => {
          this.$message.success("修改成功");
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
  }
};
</script>
